package com.jjyd.crlp.config;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;

/**
 * swagger 配置类
 */
@Configuration
public class SwaggerConfig {

    /**
     * 自动装载此文档
     * @return 返回一个文档的构建的bean
     */
    @Bean
    public Docket createApi() {
        return getDocketForDev();
    }

    /**
     * 配置swagger的扫描机制
     * @return 返回一个docket文档机制
     */
    private Docket getDocketForDev() {
        return new Docket(DocumentationType.SWAGGER_2)
                .apiInfo(apiInfo())
                .select()
                .apis(RequestHandlerSelectors.basePackage("com.jjyd.crlp"))
                .paths(PathSelectors.any())
                .build();
    }

    /**
     * api文档信息
     * @return 返回一个api文档信息
     */
    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
                .title("中俄学习平台 api 文档")
                .version("1.0")
                .build();
    }
}
